package com.kate.mall.bff.wx.controller;

import com.kate.mall.bff.wx.controller.form.QueryGoodsByCateIdForm;
import com.kate.mall.bff.wx.service.GoodsService;
import com.kate.mall.common.utils.Query;
import com.kate.mall.common.utils.R;
import com.kate.mall.log.annotation.LogAnnotation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 新梦想.陈超
 * @version 2021.2
 * @Description: {TODO}
 * @date 2022/12/21 上午10:21
 */
@RestController
@RequestMapping("/wx/goods")
@Slf4j
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @GetMapping("/detail")
    @LogAnnotation(module = "微信小程序bff")
    public R detail(Integer id) throws InterruptedException {
        log.trace("进入GoodsController的detail.....");
        return goodsService.detail(id);
    }

    @GetMapping("/count")
    @LogAnnotation(module = "微信小程序bff")
    public R count(Integer id) throws InterruptedException {
        log.trace("进入GoodsController的count.....");
        return goodsService.homeGoodsCount();
    }

    @GetMapping("/category")
    public R categoryDetail(@RequestParam(value = "id") Integer categoryId){
        //1.参数校验
        if(categoryId<=0){
            return R.badArgumentValue();
        }
        //2.调用service//3.返回数据(Model)
        return goodsService.categoryDetail(categoryId);

    }
    @GetMapping("/list")
    public R queryGoodsByCategoryId(@Validated QueryGoodsByCateIdForm goodsByCateIdForm){
        //1.参数校验

        //2.调用service//3.返回数据(Model)
        return goodsService.queryGoodsByCategoryId(goodsByCateIdForm);
    }
}
